package cn.edu.niit.servlet;

import cn.edu.niit.service.MessageService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/message/add")
public class AddMessageServlet extends HttpServlet {
    private MessageService messageService = new MessageService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String detail = req.getParameter("detail");
        String id = (String) req.getSession().getAttribute("id");
        messageService.addMessage(detail, id);
        resp.sendRedirect("/message");
    }
}
